<@app.html>
    <@app.head>
    <script>
        $(function() {
            $('#page_table').datagrid({
                fit: true,
                width: '100%',
                height: '100%',
                striped: true,
                pagination: true,
                url: "${contextPath}/security/hdw/exchange_packet_order_refund/page.htm",
                fitColumns: true,
                pageSize: 50,
                pageList: [50, 100],
                idField: 'id',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '运营商',
                            align: 'center',
                            field: 'agentName',
                            width: 40
                        },
                        {
                            title: '代理商',
                            align: 'center',
                            field: 'agencyName',
                            width: 40
                        },
                        {
                            title: '姓名',
                            align: 'center',
                            field: 'customerFullname',
                            width: 40
                        },
                        {
                            title: '手机号',
                            align: 'center',
                            field: 'customerMobile',
                            width: 40
                        },
                        {
                            title: '套餐类型',
                            align: 'center',
                            field: 'typeName',
                            width: 20
                        },
                        {
                            title: '金额(元)',
                            align: 'center',
                            field: 'money',
                            width: 20,
                            formatter: function(val) {
                                return Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '退款金额(元)',
                            align: 'center',
                            field: 'refundMoney',
                            width: 20,
                            formatter: function(val) {
                                return Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '申请退款时间',
                            align: 'center',
                            field: 'applyRefundTime',
                            width: 60
                        },
                        {
                            title: '退款时间',
                            align: 'center',
                            field: 'refundTime',
                            width: 60
                        },
                        {
                            title: '退款状态',
                            align: 'center',
                            field: 'refundStatusName',
                            width: 20
                        },
                        {
                            title: '退款人',
                            align: 'center',
                            field: 'refundOperator',
                            width: 40
                        },
                        {
                            title: '操作',
                            align: 'center',
                            field: 'action',
                            width: 60,
                            formatter: function(val, row) {
                                var html = '<a href="javascript:view(\'ID\')">查看</a>';
                                if(row.refundStatus == ${APPLY_REFUND}) {
                                    <@app.has_oper oper_code='3_14_3'>
                                        html += ' <a href="javascript:refund(\'ID\')">退款</a>';
                                    </@app.has_oper>
                                    <@app.has_oper oper_code='3_14_4'>
                                        html += ' <a href="javascript:repulse_refund(\'ID\')">拒绝退款</a>';
                                    </@app.has_oper>
                                }
                                return html.replace(/ID/g, row.id);
                            }
                        }
                    ]
                ],
                onLoadSuccess:function() {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            });
        });

        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
        }

        function query() {
            var datagrid = $('#page_table');
            var agentId_val = null;
            var agencyId_val = null;
            if ($('#agent_id').length > 0) {
                agentId_val = $('#agent_id').combotree('getValue');
            }
            if ($('#agency_id').length > 0) {
                agencyId_val = $('#agency_id').combotree('getValue');
            }
            var queryParams = {
                agentId: agentId_val,
                agencyId: agencyId_val,
                customerFullname: $('#customer_fullname').val(),
                customerMobile: $('#customer_mobile').val(),
                refundStatus: $('#status').val()
            };
            datagrid.datagrid('options').queryParams = queryParams;
            datagrid.datagrid('load');
        }

        function clears() {
            if ($('#agent_id').length > 0) {
                $('#agent_id').combotree('clear');
            }
            if ($('#agency_id').length > 0) {
                $('#agency_id').combotree('clear');
            }
            $('#customer_mobile').val(null);
            $('#customer_fullname').val(null);
            $('#status').select(0);
        }


        function reloadTree() {
            var agentId = $('#agent_id').combotree('getValue');
            var datagrid = $('#page_table');
            datagrid.datagrid('options').queryParams = {
                agentId: agentId
            };
            datagrid.datagrid('reload');
        }

        function view(id) {
            App.dialog.show({
                css: 'width:786px;height:515px;overflow:visible;',
                title: '查看',
                href: "${contextPath}/security/hdw/exchange_packet_order_refund/view.htm?id=" + id

            });
        }

        function refund(id) {
            App.dialog.show({
                css:'width:500px;height:230px;overflow:visible;',
                title:'退款',
                href:"${contextPath}/security/hdw/exchange_packet_order_refund/edit_refund.htm?id="+id,
                event: {
                    onClose: function() {
                        reload();
                    }
                }
            });

        }

        function repulse_refund(id) {
            App.dialog.show({
                css:'width:500px;height:230px;overflow:visible;',
                title:'退款',
                href:"${contextPath}/security/hdw/exchange_packet_order_refund/edit_repulse_refund.htm?id="+id,
                event: {
                    onClose: function() {
                        reload();
                    }
                }
            });

        }

    </script>
    </@app.head>
    <@app.body>
        <@app.container>
            <@app.banner/>
        <div class="main">
            <@app.menu/>
            <div class="content">
                <div class="panel search">
                    <#--<div class="float_right">-->
                        <#--<button class="btn btn_yellow" onclick="query()">搜索</button>-->
                    <#--</div>-->
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <!-- 总部 -->
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                                <td align="right">运营商：</td>
                                <td>
                                    <input name="agentId" class="easyui-combotree" editable="false"
                                           style="width: 230px; height: 28px;" id="agent_id"
                                           data-options="url:'${contextPath}/security/basic/agent/tree.htm?',method:'get',onSelect: function(rec){
                                           var url = '${contextPath}/security/hdw/agency/tree.htm?agentId='+rec.id;
                                           $('#agency_id').combotree('reload', url);},
                                           onChange:function(){
                                            $('#agency_id').combotree('clear');
                                            }
                                            "/>
                                </td>
                            </#if>
                            <#-- 如果是总部或者运营商登录 -->
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value>
                                <td align="right">代理商：</td>
                                <td>
                                    <input name="agencyId" class="easyui-combotree" editable="false"
                                           style="width: 230px; height: 28px;" id="agency_id"
                                           data-options="<#if Session['SESSION_KEY_USER'].agentId??&&Session['SESSION_KEY_USER'].agentId!=0>url:'${contextPath}/security/hdw/agency/tree.htm?agentId=${Session['SESSION_KEY_USER'].agentId}',</#if>method:'get'"
                                    />
                                </td>
                            </#if>
                            <td align="right" width="60">手机号：</td>
                            <td><input type="text" class="text" id="customer_mobile" onkeyup="query()"/></td>
                            <td align="right" width="60">姓名：</td>
                            <td><input type="text" class="text" id="customer_fullname" onkeyup="query()"/></td>
                            <td align="right" width="80">退款状态：</td>
                            <td>
                                <select style="width:90px;" id="status">
                                    <option value="">所有</option>
                                    <#list RefundStatus as e>
                                        <option value="${e.getValue()}">${e.getName()}</option>
                                    </#list>
                                </select>
                            </td>
                            <td width="15"></td>
                            <td><button class="btn btn_yellow" onclick="query()">搜索</button></td>
                            <td width="15"></td>
                            <td><button class="btn btn_green" onclick="clears()">重置</button></td>
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="toolbar clearfix">
                        <div class="float_right">
                        </div>
                        <h3>换电套餐退款记录</h3>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>

